{extend name="template/base" /}
{block name="nav"}{/block}
{block name="content"}
<div class="page-container">
    <form class="form form-horizontal" id="updatepro" method="post" action="{:\\think\\Url::build('addOrUpdate')}">
            <input type="text" class="input-text" value="{$product.pid ?? ''}" placeholder="" name="id" " style="width:0;height:0"/>
            <input type="text" class="input-text" value="{$product.stid ?? ''}" placeholder="" name="stid" " style="width:0;height:0"/>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>商品名称：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$product.pname ?? ''}" placeholder="" name="name" datatype="s" nullmsg="请填写商品名称"/>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">一级分类：</label>
            <select class="formControls col-sm-6 cascade_drop_down" id="preclass" name="preid" style="width: 150px;height: 30px" >
            </select>
            <label class="form-label col-xs-3 col-sm-3">二级分类：</label>
            <select class="formControls col-sm-6" id="subclass" name="subid" style="width: 150px;height: 30px" >
            </select>
        </div>
            <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">供应商：</label>
            <select class="formControls col-sm-6" id="sulist" name="supplier_id" style="width: 150px;height: 30px" >
            </select>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>计量单位：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$product.unit ?? ''}" placeholder="" name="unit" datatype="s" nullmsg="请填写计量单位"/>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3"><span class="c-red">*</span>条形码：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$product.barcode ?? ''}" placeholder="" name="barcode" datatype="s" nullmsg="请填写条形码"/>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">进价：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$product.pprice ?? ''}" placeholder="" name="purchase_price" ignore="ignore"/>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">售价：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$product.price ?? ''}" placeholder="" name="price" ignore="ignore"/>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">仓库库存/{$product.unit}：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$product.w_stock ?? ''}" placeholder="" name="w_stock" ignore="ignore"/>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">货架库存/{$product.unit}：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$product.s_stock ?? ''}" placeholder="" name="s_stock" ignore="ignore"/>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">库存报警/{$product.unit}：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$product.threshold ?? ''}" placeholder="" name="threshold" ignore="ignore"/>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">生产日期：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="date" name="production_date" value="{$product.prodate}"/>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">保质期/天：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$product.life ?? ''}" placeholder="" name="shelf_life" ignore="ignore"/>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">有效期至：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="date" name="valid_until" value="{$product.until}"/>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">过期报警/天：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$product.warning ?? ''}" placeholder="" name="warning_day" ignore="ignore"/>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-3 col-sm-3">备注：</label>
            <div class="formControls col-xs-6 col-sm-6">
                <input type="text" class="input-text" value="{$product.remarks ?? ''}" placeholder="" name="remarks" ignore="ignore"/>
            </div>
            <div class="col-xs-3 col-sm-3"></div>
        </div>

        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-3">
                <button type="submit" class="btn btn-primary radius">&nbsp;&nbsp;提交&nbsp;&nbsp;</button>
                <button type="button" class="btn btn-default radius ml-20" onClick="cancelAction();">&nbsp;&nbsp;取消&nbsp;&nbsp;</button>
            </div>
        </div>
    </form>
</div>
{/block}
{block name="script"}
<script type="text/javascript" src="__STATIC__/admin/lib/Validform/5.3.2/Validform.min.js"></script>
<!--<script type="text/javascript" src="__STATIC__/admin/js/jquery-2.1.0.min.js"></script>-->
<script type="text/javascript" src="__STATIC__/admin/cs-js/selected.js"></script>
<script>
    $(function () {
        $("#updatepro").Validform({
            tiptype:2,
            ajaxPost:true,
            showAllError:true,
            callback:function(ret){
                if(ret.code){
                    layer.msg(ret.msg);
                }
                else{
                    layer.msg('操作成功',{time:2000},'',location.href = '/index/Product/index');
//                    location.href = '{$Request.get.callback ?: \\think\\Url::build("/index/product/classShow")}';
                }
            }
        });
//        window.location.href = "/index/user/show";
    });
    function cancelAction(){
        window.location.href = "/index/product/index";
    }
    $.getJSON("/index/supplier/sulist", function(ret){  
        var html = "";
        var su = ret.data;  
        html += "<option value=0> --请选择-- </option>";
        if(su){
          var suid={$product.suid ?? 0};
          for(var i=0; i < su.length; i++) {  
            var s = su[i];  
            if(s.id===suid){
                html += "<option value='" + s.id + "'selected="+"selected"+">" + s.name + "</option>";
            }
            else{
                html += "<option value='" + s.id + "'>" + s.name + "</option>";
            }
          }  
        }
        $("#sulist").empty();  
//        $("#preclass option[value={$class.parent ?? 0}]").attr("selected",true);
        $("#sulist").html(function(i,origText){  
//            $("#preclass option[value={$class.parent ?? 0}]").attr("selected",true);
            return html;  
        }); 
    });
</script>
{/block}